import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shenfuhui/config/config.dart';

import '../routers/routers.dart';
import '../views/dialog_manager.dart';

///
/// 管理收货地址
///
class MineAddressManager extends StatefulWidget {
  const MineAddressManager({Key? key}) : super(key: key);

  @override
  State<MineAddressManager> createState() => _MineAddressManagerState();
}

class _MineAddressManagerState extends State<MineAddressManager> {
  var datas = [];

  @override
  void initState() {
    // TODO: implement initState
    setState(() {
      datas.add('');
      datas.add('');
      datas.add('');
    });
  }

  ///
  /// 返回普通的列表item
  ///
  Widget getListItem(int index) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10.w, horizontal: 25.w),
      decoration: BoxDecoration(
        color: (Config.colorWhite),
        borderRadius: BorderRadius.circular(10.w),
      ),
      width: double.infinity,
      padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 25.w),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                "大飞哥哥",
                style: TextStyle(fontSize: 24.sp, color: Config.colorText1),
              ),
              Text(
                "18088550000",
                style: TextStyle(fontSize: 24.sp, color: Config.colorText1),
              ),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(top: 20.w),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Icon(
                Icons.location_on_outlined,
                size: 32.w,
                color: Config.colorText1,
              ),
              Expanded(
                child: Text(
                  "广东省深圳市宝安区新安街道47区和丰小区一巷4号",
                  style: TextStyle(fontSize: 24.sp, color: Config.colorText1),
                ),
              ),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(top: 15.w),
          ),
          Divider(
            color: Config.colorDivider,
            height: 2.w,
            thickness: 2.w,
          ),
          Padding(
            padding: EdgeInsets.only(top: 15.w),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Opacity(
                opacity: index == 0 ? 1 : 0,
                child: Row(
                  children: [
                    Icon(
                      Icons.check_circle_outline,
                      color: Config.colorMain,
                      size: 26.w,
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 12.w),
                    ),
                    Text(
                      "默认地址",
                      style:
                          TextStyle(fontSize: 24.sp, color: Config.colorText1),
                    ),
                  ],
                ),
              ),
              Row(
                children: [
                  InkWell(
                    onTap: () {
                      Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          transition: TransitionType.inFromRight);
                    },
                    child: Row(
                      children: [
                        Icon(
                          Icons.edit_location_outlined,
                          color: Config.colorText1,
                          size: 25.w,
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 7.w),
                        ),
                        Text(
                          "编辑",
                          style: TextStyle(
                              fontSize: 24.sp, color: Config.colorText1),
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 20.w),
                  ),
                  InkWell(
                    onTap: () {},
                    child: Row(
                      children: [
                        Icon(
                          Icons.delete_forever,
                          color: Config.colorText1,
                          size: 25.w,
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 7.w),
                        ),
                        Text(
                          "删除",
                          style: TextStyle(
                              fontSize: 24.sp, color: Config.colorText1),
                        ),
                      ],
                    ),
                  ),
                ],
              )
            ],
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Config.colorBg2,
        appBar: AppBar(
          title: const Text('管理收货地址'),
          centerTitle: true,
        ),
        body: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: Stack(
            children: [
              Container(
                width: double.infinity,
                height: double.infinity,
                padding: EdgeInsets.only(bottom: 90.w),
                // decoration: BoxDecoration(
                //   color: (Config.colorWhite),
                //   borderRadius: BorderRadius.circular(12.w),
                // ),
                child: ListView.builder(
                  shrinkWrap: true,
                  physics: const BouncingScrollPhysics(),
                  itemCount: datas.length,
                  padding:
                      EdgeInsets.symmetric(vertical: 10.w, horizontal: 0.w),
                  itemBuilder: (BuildContext context, int index) {
                    return getListItem(index);
                  },
                ),
              ),
              Positioned(
                bottom: 0,
                child: Container(
                  width: 750.w,
                  height: 100.w,
                  padding:
                      EdgeInsets.symmetric(vertical: 8.w, horizontal: 12.w),
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () => {
                      Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          transition: TransitionType.inFromRight)
                    },
                    style:
                        ElevatedButton.styleFrom(shape: const StadiumBorder()),
                    child: const Text('添加新地址'),
                  ),
                ),
              ),
            ],
          ),
        ));
  }
}
